#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS Mail Exchange Structure
 *      Represents a DNS mail exchanger (MX) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS mail exchanger (MX) record.
			/// </summary>
			public value struct DnsMailExchangeRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsMailExchangeRecord(DNS_RECORD* record)
				{
					if (record == NULL)
					{
						ExchangeName = String::Empty;
						PreferenceValue = 0;
					}
					else
					{
						if (record->Data.MX.pNameExchange != NULL)
						{
							try
							{
							ExchangeName = gcnew String (record->Data.MX.pNameExchange);
							PreferenceValue = record->Data.MX.wPreference;
							}
							catch(...)
							{
								ExchangeName = String::Empty;
								PreferenceValue = 0;
							}
						}
					}
				}
			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsMailExchangeRecord()
				{
				}
			public:
				/// <summary>
				/// A string representing the fully qualified domain name (FQDN) of the host willing to act as a mail exchange
				/// </summary>
				/// <value>
				/// String containing the mail exchange host name, or an empty string.
				/// </value>
				String^		ExchangeName;
				/// <summary>
				/// Preference given to this resource record among others at the same owner. Lower values are preferred.
				/// </summary>
				/// <value>
				/// Preference indicator value.
				/// </value>
				short		PreferenceValue;

			};
		}
	}
}
